﻿#ifndef SENSORINPUTWIDGET_H
#define SENSORINPUTWIDGET_H

#include <QWidget>
#include <QTimer>
#include <QTextCodec>

#include "items/sensoritem.h"
#include "setcontrolstyle.h"
#include "mybutton.h"
#include "mctype/mainwidgetfunction.h"
 
#include <QDateTime>
#include <QMouseEvent>

namespace Ui {
class SensorInputWidget;
}

class SensorInputWidget : public QWidget
{
    Q_OBJECT

public:
    explicit SensorInputWidget(QWidget *parent = 0);
    ~SensorInputWidget();

private:
    Ui::SensorInputWidget *ui;

public:
    void initData();
    void setTypeLogo(QString tStyle);
    void setMainTitle(QString title);
    void setSubTitle(QString title);
    int addSensorItems(QList<SensorItem> itemList);
    void setMachine(Machine *pMc);//设置不同板卡号对应的不同Machine

public:
    void clear();

signals:
    //void siEntrySensorScan();
    //void siExitSensorScan();

public slots:
    void slotRefSensorBitmap(SensorsBitmap map);
    void slotRefSensorsDat(SensorsBitmap dat);

private slots:
    void slotOnRefTimer();
    void on_buttonPgUp_clicked();
    void on_buttonPgDn_clicked();
    void on_buttonBack_clicked();

private:
    void initControl();//初始化窗体控件，包括位置、尺寸、样式
    void initResolution();
    void initControlStyle();//初始化窗体控件样式

private:
    void refreshUi();
    void refreshSensorBtn();
    void refreshSensors();

private:
    int m_itemPerPage;
    QString m_title;
    int m_curPage;
    QList<SensorItem> m_allSensorItemList;//全部传感器信号列表   8196个
    QList<SensorItem> m_sensorItemList;//根据下位机位图过滤的传感器信号列表
    QList<SensorItem> m_itemList;//根据不同主板筛选传感器信号（20220418-rq）
    QByteArray m_sensorsDat;

    QTimer * m_pGetSenserTimer;
    QList<MyButton *> m_SensorBtnList;
    int m_sensorsTypeIdx;          // 传感器板卡的索引

private:
    void getItemList(QList <SensorItem> & ItemList);

public slots:
    void show();
    void hide();

    //鼠标事件
protected:
    void mousePressEvent(QMouseEvent *e);
    void mouseReleaseEvent(QMouseEvent *e);

private:
    int m_mousePressX;
    int m_mousePressY;
    int m_mouseReleaseX;
    int m_mouseReleaseY;

};

#endif // SENSORINPUTWIDGET_H
